//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.web.controller.exam;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.live.exam.service.LiveTaskUserService;
import com.ruoyi.live.base.domain.LiveProduct;
import com.ruoyi.live.base.domain.LiveTaskUser;
import com.ruoyi.live.base.mapper.LiveProductMapper;
import com.ruoyi.live.tool.commons.ICommons;
import com.ruoyi.live.tool.utils.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Iterator;
import java.util.List;

@Controller
@RequestMapping({"/exam"})
public class LiveTaskUserController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(LiveTaskUserController.class);
    @Autowired
    LiveTaskUserService service;
    @Autowired
    LiveProductMapper productDao;

    public LiveTaskUserController() {
    }

    @RequestMapping({"/LiveTaskUserController/index"})
    public String index() {
        return "exam/live_task_user_list";
    }

    @ResponseBody
    @RequestMapping({"/LiveTaskUserController/query"})
    public TableDataInfo query(LiveTaskUser entity) {
        this.startPage();
        List<LiveTaskUser> list = this.service.query(entity);
        Iterator var4 = list.iterator();

        while(var4.hasNext()) {
            LiveTaskUser ltu = (LiveTaskUser)var4.next();
            if (!ICommons.isNullOrEmpty(ltu.getProductId())) {
                ltu.setProName(((LiveProduct)this.productDao.selectById(ltu.getProductId())).getProductName());
            }
        }

        return this.getDataTable(list);
    }

    @ResponseBody
    @RequestMapping({"/LiveTaskUserController/add"})
    public Message add(LiveTaskUser entity) {
        try {
            this.service.addLiveTaskUser(entity);
            return new Message(true, "新增成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("", var3);
            return new Message(false, "新增失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveTaskUserController/update"})
    public Message update(LiveTaskUser entity) {
        try {
            this.service.updateLiveTaskUser(entity);
            return new Message(true, "修改成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("", var3);
            return new Message(false, "修改失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveTaskUserController/delete"})
    public Message delete(String id) {
        try {
            this.service.deleteLiveTaskUser(id.split(","));
            return new Message(true, "删除成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("", var3);
            return new Message(false, "删除失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveTaskUserController/addCountBatch"})
    public Message addCountBatch(String ids, Integer count) {
        try {
            this.service.addCountBatch(ids, count);
            return new Message(true, "增加成功");
        } catch (Exception var4) {
            var4.printStackTrace();
            return new Message(false, "增加失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/LiveTaskUserController/addCount"})
    public Message addCount(Long id) {
        try {
            this.service.addCount(id);
            return new Message(true, "增加成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, "增加失败");
        }
    }

    @RequestMapping({"/LiveTaskUserController/view"})
    public ModelAndView view(Long id, String page) {
        ModelAndView mv = new ModelAndView("exam/" + page);
        if (id != null) {
            try {
                mv.addObject("entity", this.service.getLiveTaskUser(id));
            } catch (Exception var5) {
                return (new ModelAndView("error")).addObject("tip", var5.getMessage());
            }
        }

        return mv;
    }
}
